
//有两份代码，第二份可以AC第一份理解错题意了。
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int day = 1, hour1, hour2, i = 7, j = -1;

	for (; day <= 7; day++) {
		scanf("%d%d", &hour1, &hour2);
		if (8 < hour1 + hour2)
		{
			j = day;
			goto end;
		}
	}
end:day++;
	for (; day <= 7; day++) {
		scanf("%d%d", &hour1, &hour2);
	}
	printf("%d", j);
	if (j == -1)
	{
		j = 0;
		printf("%d", j);
	}
	return 0;
}


int main()
{
	int i=0;
	int qt[7][2] = { 0 };
	for (i = 0; i < 7; i++) {
		scanf("%d%d", &qt[i][1], &qt[i][2]);
	}
	for (i = 0; i < 7; i++) {
		if (qt[i][1] + qt[i][2] > 8) {
			printf("%d", i+1);
			break;
		}
	}
	if (i == 7)
			printf("%d", 0);
	return 0;
}